﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace theRift
{
    public enum EntityType
    {
        Player,
        Enemy,
        NPC,
        Item
    }

    public class PhysicalState
    {
        protected Vector3 position;

        public Vector3 Position 
        { 
            get { return position; }
            set { position = value; } 
        }
        public float PositionY
        {
            get { return position.Y; }
            set { position.Y = value; }
        }

        public Vector3 Direction { get; set; }
        public Vector3 Velocity { get; set; }
        public Vector3 Up { get; set; }
        public Vector3 Right { get; set; }

        public float Mass { get; set; }
        public float ThrustForce { get; set; }
        public float DragFactor { get; set; }

        public Vector3 Scale { get; set; }
    }

    public class Entity : Microsoft.Xna.Framework.GameComponent
    {
        protected SimpleModel model;
        protected PhysicalState physicalState;
        protected EntityType entityType;
        protected Matrix world;

        public SimpleModel Model
        {
            get { return model; }
            set { model = value; }
        }

        public PhysicalState PhysicalState
        {
            get { return physicalState; }
            set { physicalState = value; }
        }

        public EntityType EntityType
        {
            get { return entityType; }
            set { entityType = value; }
        }

        public Entity(Game game)
            : base(game)
        {

            // Set the object's physical state
            this.physicalState = new PhysicalState();
            this.physicalState.Direction = Vector3.Forward;
            this.physicalState.Up = Vector3.Up;
            this.physicalState.Right = Vector3.Right;

            this.physicalState.Mass = 1.0f;
            this.physicalState.ThrustForce = 5000.0f;
            this.physicalState.DragFactor = 0.5f;
        }

        public override void Update(GameTime gameTime)
        {
            model.Transformation.Rotate = physicalState.Direction;
            model.Transformation.Scale = physicalState.Scale;
            model.Transformation.Translate = physicalState.Position;
            model.Transformation.Up = physicalState.Up;
            model.Transformation.Right = physicalState.Right;
        }
    }
}
